//
//  UIButton+QZAddition.m
//  QZ浪里个浪
//
//  Created by 秦－政 on 2016/10/24.
//  Copyright © 2016年 pete. All rights reserved.
//

#import "UIButton+QZAddition.h"

@implementation UIButton (QZAddition)
+(instancetype)QZ_setImgName:(NSString *)name backgroundImgName:(NSString *)backName target:(id)target action:(SEL)action
{
    UIButton *btn = [[self alloc]init];
    // 添加点击事件
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    [btn setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:[name stringByAppendingString:@"_highlighted"]] forState:UIControlStateHighlighted];
    // 设置背景图
    [btn setBackgroundImage:[UIImage imageNamed:backName] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:[backName stringByAppendingString:@"_highlighted"]] forState:UIControlStateHighlighted];
    [btn sizeToFit];
    return  btn;
}
+ (instancetype)QZ_setHighlightedImgName:(NSString *)Hname title:(NSString *)title target:(id)target action:(SEL)action
{
    UIButton *btn = [[self alloc]init];
    // 添加点击事件
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 判断
    if (Hname) {
        [btn setImage:[UIImage imageNamed:Hname] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:[Hname stringByAppendingString:@"_highlighted"]] forState:UIControlStateHighlighted];
    }
    if (title) {        
        [btn setTitle:title forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [btn setTitleColor:SLTHEMECOLOR forState:UIControlStateHighlighted];
        btn.titleLabel.font = [UIFont systemFontOfSize:SLNormalFontSize];
    }
    [btn sizeToFit];
    return btn;
}
+ (instancetype)QZ_setBackgroundImgName:(NSString *)bacImgName title:(NSString *)title fontSize:(CGFloat)fontSize titleColor:(UIColor *)color target:(id)target action:(SEL)action
{
    UIButton *btn = [[self alloc]init];
    // 添加点击事件
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[UIImage imageNamed:bacImgName] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    [btn sizeToFit];
    return btn;
}
@end
